﻿using System;

namespace VietTrips.WebUI.Helpers
{
    public static class PageNumberHelper
    {
        public static int ConvertObjectToInt(object input, int defaultValue)
        {
            int result;
            if (input != null && Int32.TryParse(input.ToString(), out result))
            {
                if (result > 0)
                {
                    return result;
                }
            }
            return defaultValue;
        }

        public static int TotalPage(int totalRecords, int offset)
        {
            return (int)Math.Ceiling((double)totalRecords / (double)offset);
        }

        public static string GetCssClassSorting(string colName, object currentSort, string defaultSort = "default")
        {
            var current = currentSort != null ? currentSort.ToString() : "";
            if (colName == defaultSort && string.IsNullOrEmpty(current)) return ("sorting_asc");
            if (colName == current) return ("sorting_asc");
            if (current == string.Concat(colName, "_desc")) return ("sorting_desc");
            return ("sorting");
        }
    }
}